<?php
set_include_path('../../../../application/default/models' . PATH_SEPARATOR . get_include_path());
require_once "Zend/Loader.php"; 
Zend_Loader::registerAutoload(); 


require_once 'application/default/controllers/DataController.php';
require_once '../../../../application/Initializer.php';

require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';

/**
 * DataController test case.
 */
class DataControllerTest extends Zend_Test_PHPUnit_ControllerTestCase {
	
	/**
	 * Prepares the environment before running a test.
	 */
	protected function setUp() {
		$this->bootstrap = array ($this, 'appBootstrap' );
		parent::setUp ();
		
	// TODO Auto-generated DataControllerTest::setUp()	
	}
	
	/**
	 * Prepares the environment before running a test.
	 */
	public function appBootstrap() {
		$this->frontController->registerPlugin ( new Initializer ( 'test' ) );
	}
	
	/**
	 * Cleans up the environment after running a test.
	 */
	protected function tearDown() {
		// TODO Auto-generated DataControllerTest::tearDown()
		parent::tearDown ();
	}
	
	/**
	 * Constructs the test case.
	 */
	public function __construct() {
		// TODO Auto-generated constructor
	}
	
	/**
	 * Tests DataController->addAction()
	 */
	public function testInsertAction() {
		
		$this->getRequest()->setParams(
			array ('_0' => null, '_1' => '2008-8-29', '_2' => 'new event', '_3' => null, '_4' => null, '_5' => '1')
		);
		$this->dispatch ( '/data/insert' );
		$this->assertController ( 'data' );
		$this->assertAction ( 'insert' );
		$this->assertNotResponseCode(404, "error 404");
		$this->assertNotNull($this->getResponse()->getBody());
		echo "<br>\r\n\t";
		echo $this->getResponse()->getBody();
	}
	
	/**
	 * Tests DataController->deleteAction()
	 */
	public function testDeleteAction() {
		$this->getRequest()->setParams(
			array ('_0' => 69)
		);
		$this->dispatch ( '/data/delete' );
		$this->assertController ( 'data' );
		$this->assertAction ( 'delete' );
		$this->assertNotResponseCode(404, "error 404");
		$this->assertNotNull($this->getResponse()->getBody());
		echo "<br>\r\n\t";
		echo $this->getResponse()->getBody();
			
	}
	
	/**
	 * Tests DataController->errorAction()
	 */
	public function testErrorAction() {
		$this->dispatch ( '/data/error' );
		$this->assertController ( 'data' );
		$this->assertAction ( 'error' );
	}
	
	/**
	 * Tests DataController->infoAction()
	 */
	public function testInfoAction() {
		$this->dispatch ( '/data/info' );
		$this->assertController ( 'data' );
		$this->assertAction ( 'info' );
		echo $this->getResponse()->getBody();	
	}
	
	/**
	 * Tests DataController->selectAction()
	 */
	public function testSelectAction() {
		$this->getRequest()->setParam('limit', '2');
		$this->dispatch ( '/data/select' );
		$this->assertController ( 'data' );
		$this->assertAction ( 'select' );
		$this->assertNotNull($this->getResponse()->getBody());
		echo $this->getResponse()->getBody();
	}
	
	/**
	 * Tests DataController->updateAction()
	 */
	public function testUpdateAction() {
		$this->getRequest()->setParams(
			array ('_0' => 66, '_1' => '2008-8-30', '_2' => 'new event', '_3' => null, '_4' => null, '_5' => '1', 
				   '_o0' => 56, '_o1' => '2008-8-20', '_o2' => 'new event', '_o3' => null, '_o4' => null, '_o5' => '1')
		);		
		
		$this->dispatch ( '/data/update' );
		$this->assertController ( 'data' );
		$this->assertAction ( 'update' );
		$this->assertNotResponseCode(404, "error 404");
		$this->assertNotNull($this->getResponse()->getBody());
		echo "<br>\r\n\t";
		echo $this->getResponse()->getBody();
	}
}

